<?php
namespace Admin\Controller;

class UserController extends AdminController {
    public function index(){
        $p = I('get.p',1);
        $user= D('User','Service');
        $params['page'] = $p;
        $params['step'] = 10;
        $params['where'] = 'status = 1';
        $dataArr=$user->GetUserList($params);
        $page = $dataArr['page'];
        $data = $dataArr['data'];

        $this->assign('page',$page);// 赋值分页输出
    	$this->assign('title','用户管理');
        $this->assign('data',$data);
    	$this->display();
    }

    public function AddUser(){
        $this->assign('title','新增用户');
        if($_POST){
            $username = I('post.username');
            $email = I('post.email');
            $user=D("User","Service");
            $resUsername = $user->GetUserByUserName($username);
            if($resUsername){
                $popMSG['title'] = '错误';
                $popMSG['msg'] = '用户名已被使用';
                $this->assign('popMSG',$popMSG);
                $this->display();
                return ;
            }
            $resEmail = $user->GetUserByEmail($email);
            if($resEmail){
                $popMSG['title'] = '错误';
                $popMSG['msg'] = 'Email已被使用';
                $this->assign('popMSG',$popMSG);
                $this->display();
                return ;
            }
            $res=$user->AddUser();
            if($res){
                $this->redirect('User/index');
            }else{
                $popMSG['title'] = '错误';
                $popMSG['msg'] = '新增用户出错';
                $this->assign('popMSG',$popMSG);
            }
        }

        $this->display();
    }
}